module libuv.uv ;


public import 
	libuv.uvprivate.uvwin ;

extern(C) :

alias char*	uv_charptr ;
alias char  	uv_char ;
alias char  	uv_charvolatile ;
alias ubyte 	uv_uchar ;
alias ubyte 	uv_ubyte;
alias byte 		uv_byte;

alias ushort uv_ushort;

alias uint 	uv_uint ;
alias int 	uv_int;

version(Win32) {
	alias uint uv_ulong;
	alias int  uv_long ;
}

alias long uv_int64;
alias ulong uv_uint64;
alias double uv_double;

enum uv_err_code {
	// UV_ERRNO_MAP(UV_ERRNO_GEN)
	UV_MAX_ERRORS
} ;


enum uv_handle_type{
	UV_UNKNOWN_HANDLE = 0,
	/*
	#define XX(uc, lc) UV_##uc,
	UV_HANDLE_TYPE_MAP(XX)
	#undef XX
	*/
	UV_FILE,
	UV_HANDLE_TYPE_MAX
} 

enum  uv_req_type {
	UV_UNKNOWN_REQ = 0,
	 /*
	#define XX(uc, lc) UV_##uc,
	UV_REQ_TYPE_MAP(XX)
	#undef XX
	 */
	UV_REQ_TYPE_PRIVATE,
	UV_REQ_TYPE_MAX,
} 

enum   uv_run_mode {
	UV_RUN_DEFAULT = 0,
	UV_RUN_ONCE,
	UV_RUN_NOWAIT
}

uv_uint uv_version();
uv_charptr uv_version_string();

uv_loop_t* uv_loop_new();
void uv_loop_delete(uv_loop_t*);
uv_loop_t* uv_default_loop();
uv_int uv_run(uv_loop_t*, uv_run_mode mode);
void uv_stop(uv_loop_t*);
void uv_ref(uv_handle_t*);
void uv_unref(uv_handle_t*);
void uv_update_time(uv_loop_t*);
uv_int64 uv_now(uv_loop_t*);

uv_int uv_backend_fd(const(uv_loop_t*));
uv_int uv_backend_timeout(const(uv_loop_t*));


// typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size);
alias uv_buf_t function(uv_handle_t* handle, size_t suggested_size) uv_alloc_cb ;
// typedef void (*uv_read_cb)(uv_stream_t* stream, ptrdiff_t nread, uv_buf_t buf);
alias void function(uv_stream_t* stream, ptrdiff_t nread, uv_buf_t buf) uv_read_cb ;
// typedef void (*uv_read2_cb)(uv_pipe_t* pipe, ptrdiff_t nread, uv_buf_t buf,uv_handle_type pending);
alias void function(uv_pipe_t* pipe, ptrdiff_t nread, uv_buf_t buf, uv_handle_type pendingf) uv_read2_cb ;


//typedef void (*uv_write_cb)(uv_write_t* req, uv_int status);
alias void function(uv_write_t* req, uv_int status) uv_write_cb ;
//typedef void (*uv_connect_cb)(uv_connect_t* req, uv_int status);
alias void function(uv_connect_t* req, uv_int status) uv_connect_cb ;
//typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, uv_int status);
alias void function(uv_shutdown_t* req, uv_int status) uv_shutdown_cb ;
//typedef void (*uv_connection_cb)(uv_stream_t* server, uv_int status);
alias void function(uv_stream_t* server, uv_int status) uv_connection_cb ;
//typedef void (*uv_close_cb)(uv_handle_t* handle);
alias void function(uv_handle_t* handle) uv_close_cb ;
//typedef void (*uv_poll_cb)(uv_poll_t* handle, uv_int status, uv_int events);
alias void function(uv_poll_t* handle, uv_int status, uv_int events) uv_poll_cb ;
//typedef void (*uv_timer_cb)(uv_timer_t* handle, uv_int status);
alias void function(uv_timer_t* handle, uv_int status) uv_timer_cb ;
/* TODO: do these really need a status argument? */
//typedef void (*uv_async_cb)(uv_async_t* handle, uv_int status);
alias void function(uv_async_t* handle, uv_int status) uv_async_cb ;
//typedef void (*uv_prepare_cb)(uv_prepare_t* handle, uv_int status);
alias void function(uv_prepare_t* handle, uv_int status) uv_prepare_cb ;
//typedef void (*uv_check_cb)(uv_check_t* handle, uv_int status);
alias void function(uv_check_t* handle, uv_int status) uv_check_cb ;
//typedef void (*uv_idle_cb)(uv_idle_t* handle, uv_int status);
alias void function(uv_idle_t* handle, uv_int status) uv_idle_cb ;
//typedef void (*uv_exit_cb)(uv_process_t*, uv_int exit_status, uv_int term_signal);
alias void function(uv_process_t*, uv_int exit_status, uv_int term_signal) uv_exit_cb ;
//typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg);
alias void function(uv_handle_t* handle, void* arg) uv_walk_cb ;
//typedef void (*uv_fs_cb)(uv_fs_t* req);
alias void function(uv_fs_t* req) uv_fs_cb ;
//typedef void (*uv_work_cb)(uv_work_t* req);
alias void function(uv_work_t* req) uv_work_cb ;
//typedef void (*uv_after_work_cb)(uv_work_t* req, uv_int status);
alias void function(uv_work_t* req, uv_int status) uv_after_work_cb ;
//typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req, uv_int status, addrinfo* res);
alias void function(uv_getaddrinfo_t* req, uv_int status,  addrinfo* res) uv_getaddrinfo_cb ;


struct uv_timespec_t{
  uv_long tv_sec;
  uv_long tv_nsec;
} ;

struct uv_stat_t{
  uv_int64 st_dev;
  uv_int64 st_mode;
  uv_int64 st_nlink;
  uv_int64 st_uid;
  uv_int64 st_gid;
  uv_int64 st_rdev;
  uv_int64 st_ino;
  uv_int64 st_size;
  uv_int64 st_blksize;
  uv_int64 st_blocks;
  uv_timespec_t st_atim;
  uv_timespec_t st_mtim;
  uv_timespec_t st_ctim;
}

//typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle,const(char*) filename, uv_int events, uv_int status);
alias void function(uv_fs_event_t* handle, uv_charptr filename, uv_int events, uv_int status) uv_fs_event_cb ;
//typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle, uv_int status,const uv_stat_t* prev, const uv_stat_t* curr);
alias void function(uv_fs_poll_t* handle, uv_int status,const(uv_stat_t*) prev, const(uv_stat_t*) curr) uv_fs_poll_cb ;
//typedef void (*uv_signal_cb)(uv_signal_t* handle, uv_int signum);
alias void function(uv_signal_t* handle, uv_int signum) uv_signal_cb ;

enum uv_membership{
  UV_LEAVE_GROUP = 0,
  UV_JOIN_GROUP
} ;


struct uv_err_s {
	/* read-only */
	uv_err_code code;
	/* private */
	uv_int sys_errno_;
};
alias uv_err_s uv_err_t;

uv_err_t uv_last_error(uv_loop_t*);
uv_charptr uv_strerror(uv_err_t err);
uv_charptr uv_err_name(uv_err_t err);

mixin template UV_REQ_FIELDS(){
	void* data;
	uv_req_type type; 
	void* active_queue[2]; 
	mixin UV_REQ_PRIVATE_FIELDS;
}

struct uv_req_s {
  mixin UV_REQ_FIELDS; // uv_req_s
};
alias uv_req_s uv_req_t;

mixin UV_PRIVATE_REQ_TYPES;

/* Platform-specific request types */

mixin template UV_HANDLE_FIELDS(){
  uv_close_cb close_cb;
  void* data;
  /* read-only */ 
  uv_loop_t* loop;
  uv_handle_type type; 
  /* private */ 
  void* handle_queue[2]; 
  mixin UV_HANDLE_PRIVATE_FIELDS;
}

uv_int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb);
struct uv_shutdown_s {
   mixin UV_REQ_FIELDS;
   uv_stream_t* handle;
   uv_shutdown_cb cb;
  mixin UV_SHUTDOWN_PRIVATE_FIELDS;
};
alias uv_shutdown_s uv_shutdown_t;

struct uv_handle_s {
  mixin UV_HANDLE_FIELDS;
};
alias uv_handle_s uv_handle_t;

size_t uv_handle_size(uv_handle_type type);
size_t uv_req_size(uv_req_type type);
uv_int uv_is_active(const uv_handle_t* handle);
void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
uv_buf_t uv_buf_init(char* base, uv_uint len);
size_t uv_strlcpy(char* dst, const(char*) src, size_t size);
size_t uv_strlcat(char* dst, const(char*) src, size_t size);


mixin template UV_STREAM_FIELDS(){
  /* number of bytes queued for writing */
  size_t write_queue_size;
  uv_alloc_cb alloc_cb;
  uv_read_cb read_cb;
  uv_read2_cb read2_cb;
  /* private */
  mixin UV_STREAM_PRIVATE_FIELDS;
}

struct uv_stream_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_STREAM_FIELDS;
};
alias uv_stream_s uv_stream_t;

uv_int uv_listen(uv_stream_t* stream, uv_int backlog, uv_connection_cb cb);
uv_int uv_accept(uv_stream_t* server, uv_stream_t* client);
uv_int uv_read_start(uv_stream_t*, uv_alloc_cb alloc_cb, uv_read_cb read_cb);
uv_int uv_read_stop(uv_stream_t*);
uv_int uv_read2_start(uv_stream_t*, uv_alloc_cb alloc_cb, uv_read2_cb read_cb);
uv_int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t* bufs, uv_int bufcnt, uv_write_cb cb);
uv_int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t* bufs, uv_int bufcnt, uv_stream_t* send_handle, uv_write_cb cb);

struct uv_write_s {
  mixin UV_REQ_FIELDS;
  uv_write_cb cb;
  uv_stream_t* send_handle;
  uv_stream_t* handle;
  mixin UV_WRITE_PRIVATE_FIELDS;
};
alias uv_write_s uv_write_t;

uv_int uv_is_readable(const(uv_stream_t*) handle);
uv_int uv_is_writable(const(uv_stream_t*) handle);
uv_int uv_is_closing(const(uv_handle_t*) handle);

struct uv_tcp_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_STREAM_FIELDS;
  mixin UV_TCP_PRIVATE_FIELDS;
};
alias uv_tcp_s uv_tcp_t;


uv_int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
uv_int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
uv_int uv_tcp_nodelay(uv_tcp_t* handle, uv_int enable);
uv_int uv_tcp_keepalive(uv_tcp_t* handle, uv_int enable, uv_uint delay);
uv_int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, uv_int enable);
uv_int uv_tcp_bind(uv_tcp_t* handle, sockaddr_in);
uv_int uv_tcp_bind6(uv_tcp_t* handle, sockaddr_in6);
uv_int uv_tcp_getsockname(uv_tcp_t* handle, sockaddr* name, uv_int* namelen);
uv_int uv_tcp_getpeername(uv_tcp_t* handle, sockaddr* name, uv_int* namelen);
uv_int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, sockaddr_in address, uv_connect_cb cb);
uv_int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, sockaddr_in6 address, uv_connect_cb cb);

struct uv_connect_s {
  mixin UV_REQ_FIELDS;
  uv_connect_cb cb;
  uv_stream_t* handle;
  mixin UV_CONNECT_PRIVATE_FIELDS;
};
alias uv_connect_s uv_connect_t;

enum uv_udp_flags {
  UV_UDP_IPV6ONLY = 1,
  UV_UDP_PARTIAL = 2
};

//typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, uv_int status);
alias void function(uv_udp_send_t* req, uv_int status) uv_udp_send_cb ;
//typedef void (*uv_udp_recv_cb)(uv_udp_t* handle, ptrdiff_t nread, uv_buf_t buf,struct sockaddr* addr, unsigned flags);
alias void function(uv_udp_t* handle, ptrdiff_t nread, uv_buf_t buf,sockaddr* addr, uv_uint flags) uv_udp_recv_cb ;

struct uv_udp_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_UDP_PRIVATE_FIELDS;
};
alias uv_udp_s uv_udp_t;
struct uv_udp_send_s {
  mixin UV_REQ_FIELDS;
  uv_udp_t* handle;
  uv_udp_send_cb cb;
  mixin UV_UDP_SEND_PRIVATE_FIELDS;
};
alias uv_udp_send_s uv_udp_send_t;

 uv_int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
 uv_int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
 uv_int uv_udp_bind(uv_udp_t* handle,  sockaddr_in addr, uv_uint flags);
 uv_int uv_udp_bind6(uv_udp_t* handle,  sockaddr_in6 addr,  uv_uint flags);
 uv_int uv_udp_getsockname(uv_udp_t* handle,  sockaddr* name, uv_int* namelen);
 uv_int uv_udp_set_membership(uv_udp_t* handle,const(char*) multicast_addr, const(char*) interface_addr, uv_membership membership);
 uv_int uv_udp_set_multicast_loop(uv_udp_t* handle, uv_int on);
 uv_int uv_udp_set_multicast_ttl(uv_udp_t* handle, uv_int ttl);
 uv_int uv_udp_set_broadcast(uv_udp_t* handle, uv_int on);
 uv_int uv_udp_set_ttl(uv_udp_t* handle, uv_int ttl);
 uv_int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], uv_int bufcnt,  sockaddr_in addr, uv_udp_send_cb send_cb);
 uv_int uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle,  uv_buf_t bufs[], uv_int bufcnt,  sockaddr_in6 addr, uv_udp_send_cb send_cb);
 uv_int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb);
 uv_int uv_udp_recv_stop(uv_udp_t* handle);

struct uv_tty_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_STREAM_FIELDS;
 mixin UV_TTY_PRIVATE_FIELDS;
};
alias uv_tty_s uv_tty_t;

uv_int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, uv_int readable);
uv_int uv_tty_set_mode(uv_tty_t*, uv_int mode);
void uv_tty_reset_mode();
uv_int uv_tty_get_winsize(uv_tty_t*, uv_int* width, uv_int* height);
uv_handle_type uv_guess_handle(uv_file file);

struct uv_pipe_s {
   mixin UV_HANDLE_FIELDS;
   mixin UV_STREAM_FIELDS;
  uv_int ipc; /* non-zero if this pipe is used for passing handles */
   mixin UV_PIPE_PRIVATE_FIELDS;
};
alias uv_pipe_s uv_pipe_t;

uv_int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, uv_int ipc);
uv_int uv_pipe_open(uv_pipe_t*, uv_file file);
uv_int uv_pipe_bind(uv_pipe_t* handle, const(char*) name);
void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, const(char*) name, uv_connect_cb cb);
void uv_pipe_pending_instances(uv_pipe_t* handle, uv_int count);

struct uv_poll_s {
   mixin UV_HANDLE_FIELDS;
  uv_poll_cb poll_cb;
   mixin UV_POLL_PRIVATE_FIELDS;
};
alias uv_poll_s uv_poll_t;

enum uv_poll_event {
  UV_READABLE = 1,
  UV_WRITABLE = 2
};

 uv_int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, uv_int fd);
 uv_int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle, uv_os_sock_t socket);
 uv_int uv_poll_start(uv_poll_t* handle, uv_int events, uv_poll_cb cb);
 uv_int uv_poll_stop(uv_poll_t* handle);
struct uv_prepare_s {
 mixin UV_HANDLE_FIELDS;
  mixin UV_PREPARE_PRIVATE_FIELDS;
};
alias uv_prepare_s uv_prepare_t;

 uv_int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare);
 uv_int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb);
 uv_int uv_prepare_stop(uv_prepare_t* prepare);
struct uv_check_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_CHECK_PRIVATE_FIELDS;
};
alias uv_check_s uv_check_t;

 uv_int uv_check_init(uv_loop_t*, uv_check_t* check);
 uv_int uv_check_start(uv_check_t* check, uv_check_cb cb);
 uv_int uv_check_stop(uv_check_t* check);
struct uv_idle_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_IDLE_PRIVATE_FIELDS;
};
alias uv_idle_s uv_idle_t;

 uv_int uv_idle_init(uv_loop_t*, uv_idle_t* idle);

 uv_int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb);

 uv_int uv_idle_stop(uv_idle_t* idle);

struct uv_async_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_ASYNC_PRIVATE_FIELDS;
};
alias uv_async_s uv_async_t;

 uv_int uv_async_init(uv_loop_t*, uv_async_t* async, uv_async_cb async_cb);
 uv_int uv_async_send(uv_async_t* async);
struct uv_timer_s {
  mixin UV_HANDLE_FIELDS;
  mixin UV_TIMER_PRIVATE_FIELDS;
};
alias uv_timer_s uv_timer_t;

 uv_int uv_timer_init(uv_loop_t*, uv_timer_t* handle);
 uv_int uv_timer_start(uv_timer_t* handle, uv_timer_cb cb, uv_int64 timeout, uv_int64 repeat);
 uv_int uv_timer_stop(uv_timer_t* handle);
 uv_int uv_timer_again(uv_timer_t* handle);
 void uv_timer_set_repeat(uv_timer_t* handle, uv_int64 repeat);
 uv_int64 uv_timer_get_repeat(const uv_timer_t* handle);

struct uv_getaddrinfo_s {
  mixin UV_REQ_FIELDS;
  uv_loop_t* loop;
  mixin UV_GETADDRINFO_PRIVATE_FIELDS;
};
alias uv_getaddrinfo_s uv_getaddrinfo_t;

 uv_int uv_getaddrinfo(uv_loop_t* loop,
			     uv_getaddrinfo_t* req,
			     uv_getaddrinfo_cb getaddrinfo_cb,
			    const(char*) node,
			    const(char*) service,
			     const addrinfo* hints);


void uv_freeaddrinfo(addrinfo* ai);

enum uv_stdio_flags {
  UV_IGNORE         = 0x00,
  UV_CREATE_PIPE    = 0x01,
  UV_INHERIT_FD     = 0x02,
  UV_INHERIT_STREAM = 0x04,
  UV_READABLE_PIPE  = 0x10,
  UV_WRITABLE_PIPE  = 0x20
} ;

struct uv_stdio_container_s {
	uv_stdio_flags flags;
	union {
		uv_stream_t* __stream;
		uv_int 	__fd;
	} /*data;*/
} ;
alias uv_stdio_container_s uv_stdio_container_t;

enum uv_process_flags {
  UV_PROCESS_SETUID = (1 << 0),
  UV_PROCESS_SETGID = (1 << 1),
  UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2),
  UV_PROCESS_DETACHED = (1 << 3),
  UV_PROCESS_WINDOWS_HIDE = (1 << 4)
};

struct uv_process_options_s {
  uv_exit_cb exit_cb;
  const(char*) file;
  char** args;
  char** env;
  char* cwd;
  uv_uint flags;
  uv_int stdio_count;
  uv_stdio_container_t* stdio;
  uv_uid_t uid;
  uv_gid_t gid;
} 
alias uv_process_options_s uv_process_options_t;

struct uv_process_s {
  mixin UV_HANDLE_FIELDS;
  uv_exit_cb exit_cb;
  uv_int pid;
  mixin UV_PROCESS_PRIVATE_FIELDS;
};
alias uv_process_s uv_process_t;

 uv_int uv_spawn(uv_loop_t*, uv_process_t*, uv_process_options_t options);
 uv_int uv_process_kill(uv_process_t*, uv_int signum);
 uv_err_t uv_kill(uv_int pid, uv_int signum);
struct uv_work_s {
   mixin UV_REQ_FIELDS;
  uv_loop_t* loop;
  uv_work_cb work_cb;
  uv_after_work_cb after_work_cb;
  mixin UV_WORK_PRIVATE_FIELDS;
};
alias uv_work_s uv_work_t;

 uv_int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_after_work_cb after_work_cb);
 uv_int uv_cancel(uv_req_t* req);


struct uv_cpu_times_s {
	uv_int64 user;
	uv_int64 nice;
	uv_int64 sys;
	uv_int64 idle;
	uv_int64 irq;
} 
struct uv_cpu_info_s {
	uv_charptr model;
	uv_int speed;
	uv_cpu_times_s cpu_times;
};
alias uv_cpu_info_s uv_cpu_info_t;

struct uv_interface_address_s {
	char* name;
	uv_int is_internal;
	
	union {
		sockaddr_in 	__address4;
		sockaddr_in6 	__address6;
	} /*address;*/
};
alias uv_interface_address_s uv_interface_address_t;

char** uv_setup_args(uv_int argc, char** argv);
uv_err_t uv_get_process_title(char* buffer, size_t size);
uv_err_t uv_set_process_title(const(char*) title);
uv_err_t uv_resident_set_memory(size_t* rss);
uv_err_t uv_uptime(uv_double* uptime);

 uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, uv_int* count);
 void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, uv_int count);

uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,  uv_int* count);
void uv_free_interface_addresses(uv_interface_address_t* addresses, uv_int count);

enum uv_fs_type{
  UV_FS_UNKNOWN = -1,
  UV_FS_CUSTOM,
  UV_FS_OPEN,
  UV_FS_CLOSE,
  UV_FS_READ,
  UV_FS_WRITE,
  UV_FS_SENDFILE,
  UV_FS_STAT,
  UV_FS_LSTAT,
  UV_FS_FSTAT,
  UV_FS_FTRUNCATE,
  UV_FS_UTIME,
  UV_FS_FUTIME,
  UV_FS_CHMOD,
  UV_FS_FCHMOD,
  UV_FS_FSYNC,
  UV_FS_FDATASYNC,
  UV_FS_UNLINK,
  UV_FS_RMDIR,
  UV_FS_MKDIR,
  UV_FS_RENAME,
  UV_FS_READDIR,
  UV_FS_LINK,
  UV_FS_SYMLINK,
  UV_FS_READLINK,
  UV_FS_CHOWN,
  UV_FS_FCHOWN
} ;

/* uv_fs_t is a subclass of uv_req_t */
struct uv_fs_s {
  mixin UV_REQ_FIELDS;
  uv_fs_type fs_type;
  uv_loop_t* loop;
  uv_fs_cb cb;
  ptrdiff_t result;
  void* ptr;
  const(char*) path;
  uv_err_code errorno;
  uv_stat_t statbuf; 
  mixin UV_FS_PRIVATE_FIELDS;
};
alias uv_fs_s uv_fs_t;

 void uv_fs_req_cleanup(uv_fs_t* req);
 uv_int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
 uv_int uv_fs_open(uv_loop_t* loop, uv_fs_t* req,const(char*) path,  uv_int flags, uv_int mode, uv_fs_cb cb);
 uv_int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, size_t length, uv_int64 offset, uv_fs_cb cb);
 uv_int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req,const(char*) path, uv_fs_cb cb);
 uv_int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, size_t length, uv_int64 offset, uv_fs_cb cb);
 uv_int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req,const(char*) path, uv_int mode, uv_fs_cb cb);
 uv_int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req,const(char*) path, uv_fs_cb cb);
 uv_int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const(char*) path, uv_int flags, uv_fs_cb cb);
 uv_int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req,const(char*) path,uv_fs_cb cb);
 uv_int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
 uv_int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req,const(char*) path, const(char*) new_path, uv_fs_cb cb);
 uv_int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
 uv_int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb);
 uv_int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_int64 offset, uv_fs_cb cb);
 uv_int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd, uv_file in_fd, uv_int64 in_offset, size_t length, uv_fs_cb cb);
 uv_int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req,const(char*) path, uv_int mode, uv_fs_cb cb);
 uv_int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req,const(char*) path, uv_double atime, uv_double mtime, uv_fs_cb cb);
 uv_int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_double atime, uv_double mtime, uv_fs_cb cb);
 uv_int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req,const(char*) path,uv_fs_cb cb);
 uv_int uv_fs_link(uv_loop_t* loop, uv_fs_t* req,const(char*) path,const(char*) new_path, uv_fs_cb cb);
const UV_FS_SYMLINK_DIR         = 0x0001;
const UV_FS_SYMLINK_JUNCTION  =  0x0002 ;
 uv_int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req,const(char*) path, const(char*) new_path, uv_int flags, uv_fs_cb cb);
 uv_int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req,const(char*) path, uv_fs_cb cb);
 uv_int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_int mode, uv_fs_cb cb);
 uv_int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req,const(char*) path, uv_int uid, uv_int gid, uv_fs_cb cb);
 uv_int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_int uid, uv_int gid, uv_fs_cb cb);


enum uv_fs_event {
  UV_RENAME = 1,
  UV_CHANGE = 2
};

struct uv_fs_event_s {
  mixin UV_HANDLE_FIELDS;
  char* filename;
  mixin UV_FS_EVENT_PRIVATE_FIELDS;
};
alias uv_fs_event_s uv_fs_event_t;

struct uv_fs_poll_s {
  mixin UV_HANDLE_FIELDS;
  void* poll_ctx;
};
alias uv_fs_poll_s uv_fs_poll_t;

 uv_int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
 uv_int uv_fs_poll_start(uv_fs_poll_t* handle, uv_fs_poll_cb poll_cb,const(char*) path, uv_uint interval);
 uv_int uv_fs_poll_stop(uv_fs_poll_t* handle);

struct uv_signal_s {
  mixin UV_HANDLE_FIELDS;
  uv_signal_cb signal_cb;
  uv_int signum;
  mixin UV_SIGNAL_PRIVATE_FIELDS;
};
alias uv_signal_s uv_signal_t;

 uv_int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
 uv_int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb,  uv_int signum);
 uv_int uv_signal_stop(uv_signal_t* handle);
 void uv_loadavg(uv_double avg[3]);

enum uv_fs_event_flags {
 UV_FS_EVENT_WATCH_ENTRY = 1,
  UV_FS_EVENT_STAT = 2,
  UV_FS_EVENT_RECURSIVE = 3
};

uv_int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,const(char*) filename, uv_fs_event_cb cb, uv_int flags);

sockaddr_in uv_ip4_addr(const(char*) ip, uv_int port);
sockaddr_in6 uv_ip6_addr(const(char*) ip, uv_int port);

uv_int uv_ip4_name(sockaddr_in* src, char* dst, size_t size);
uv_int uv_ip6_name(sockaddr_in6* src, char* dst, size_t size);

uv_err_t uv_inet_ntop(uv_int af, const void* src, char* dst, size_t size);
uv_err_t uv_inet_pton(uv_int af,const(char*) src, void* dst);

uv_int uv_exepath(char* buffer, size_t* size);
uv_err_t uv_cwd(char* buffer, size_t size);
uv_err_t uv_chdir(const(char*) dir);
uv_int64 uv_get_free_memory();
uv_int64 uv_get_total_memory();
uv_int64 uv_hrtime();
void uv_disable_stdio_inheritance();
uv_int uv_dlopen(const(char*) filename, uv_lib_t* lib);
void uv_dlclose(uv_lib_t* lib);
uv_int uv_dlsym(uv_lib_t* lib,const(char*) name, void** ptr);
const(char*) uv_dlerror(uv_lib_t* lib);
uv_int uv_mutex_init(uv_mutex_t* handle);
void uv_mutex_destroy(uv_mutex_t* handle);
void uv_mutex_lock(uv_mutex_t* handle);
uv_int uv_mutex_trylock(uv_mutex_t* handle);
void uv_mutex_unlock(uv_mutex_t* handle);
uv_int uv_rwlock_init(uv_rwlock_t* rwlock);
void uv_rwlock_destroy(uv_rwlock_t* rwlock);
void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
uv_int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
uv_int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
uv_int uv_sem_init(uv_sem_t* sem, uv_uint value);
void uv_sem_destroy(uv_sem_t* sem);
void uv_sem_post(uv_sem_t* sem);
void uv_sem_wait(uv_sem_t* sem);
uv_int uv_sem_trywait(uv_sem_t* sem);
uv_int uv_cond_init(uv_cond_t* cond);
void uv_cond_destroy(uv_cond_t* cond);
void uv_cond_signal(uv_cond_t* cond);
void uv_cond_broadcast(uv_cond_t* cond);
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
uv_int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex,uv_int64 timeout);
uv_int uv_barrier_init(uv_barrier_t* barrier, uv_uint count);
void uv_barrier_destroy(uv_barrier_t* barrier);
void uv_barrier_wait(uv_barrier_t* barrier);
void uv_once(uv_once_t* guard, void function() callback);
uv_int uv_thread_create(uv_thread_t *tid,void function(void *arg) entry, void *arg);
uv_ulong uv_thread_self();
uv_int uv_thread_join(uv_thread_t *tid);

/*
union uv_any_handle {
  UV_HANDLE_TYPE_MAP(XX)
};

union uv_any_req {
  UV_REQ_TYPE_MAP(XX)
};
*/

struct uv_loop_s {
  void* data;
  uv_err_t last_err;
  uv_uint active_handles;
  void* handle_queue[2];
  void* active_reqs[2];
  uv_uint stop_flag;
  mixin UV_LOOP_PRIVATE_FIELDS;
};
alias uv_loop_s uv_loop_t;